﻿@{
    ViewBag.Title = "Form";
    Layout = "~/Views/Shared/_Form.cshtml";
}
<div class="layuimini-container">
    <div class="layuimini-main">
        <fieldset class="table-search-fieldset" id="searchField">
            <div>
                <form class="layui-form layui-form-pane">
                    <div class="layui-inline">
                        <label class="layui-form-label">计划时间</label>
                        <div class="layui-input-inline">
                            <input type="text" id="F_PlanTime" name="F_PlanTime" readonly autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label required">物料</label>
                        <div class="layui-input-inline">
                            <select id="F_MaterialId" name="F_MaterialId" disabled>
                            </select>
                        </div>
                    </div>
                </form>
            </div>
        </fieldset>
        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container" id="toolbar">
                <button id="NF-add" name="NF-add" authorize class="layui-btn layui-btn-sm" lay-event="add"><i class="layui-icon">&#xe654;</i>新增</button>
                <button id="NF-edit" name="NF-edit" authorize class="layui-btn layui-btn-sm layui-btn-warm layui-hide" lay-event="edit"><i class="layui-icon">&#xe642;</i>修改</button>
                <button id="NF-delete" name="NF-delete" authorize class="layui-btn layui-btn-sm layui-btn-danger layui-hide" lay-event="delete"> <i class="layui-icon">&#xe640;</i>删除</button>
                <button id="NF-enabled" name="NF-enabled" class="layui-btn layui-btn-sm data-enabled-btn layui-hide" lay-event="enabled"> <i class="fa fa-play-circle"></i>启用</button>
            </div>
        </script>
        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>
    </div>
</div>
<script>
    layui.use(['jquery', 'form', 'table', 'commonTable', 'common', 'optimizeSelectOption'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table, commonTable = layui.commonTable
        common = layui.common;
        var keyValue = $.request("keyValue");
        var materialId = $.request("materialId");
        $("#F_MaterialId").bindSelect({
            url: "/MaterialManage/Material/GetListJson",
            id: "F_Id",
            text: "F_MaterialName"
        });
        $("#F_MaterialId").val(materialId);
        $("#F_PlanTime").val(keyValue);
        form.render();
        parent.$(".layui-layer-title")[0].innerText = parent.$(".layui-layer-title")[0].innerText+'（' + $("#F_MaterialId option:selected").text() + ','+keyValue+'）';
        commonTable.rendertable({
            elem: '#currentTableId',
            id: 'currentTableId',
            url: '/PlanManage/OutStoragePlan/GetListJson',
            where: { keyValue: keyValue, materialId: materialId },
            search: false,
            height: 'full-100',
            cols: [[
                //此处需修改
                { type: "radio", width: 50 },
                {
                    field: 'F_IsUserEdit', title: '实际', width: 100, sort: true, filter: true,
                    templet: function (d) {
                        if (d.F_IsUserEdit == true) {
                            return "<span class='layui-btn layui-btn-normal layui-btn-xs'>是</span>";
                        } else {
                            return "<span class='layui-btn layui-btn-warm layui-btn-xs'>否</span>";
                        }
                    }
                },
                { field: 'F_OutStorageCode', title: '出库单编号', width: 170, sort: true, filter: true },
                {
                    field: 'F_OutStorageState', title: '出库单状态', width: 120, sort: true, filter: true,
                    templet: function (d) {
                        if (d.F_OutStorageState == 0) {
                            return "<span class='layui-btn layui-btn-normal layui-btn-xs'>等待中</span>";
                        }
                        if (d.F_OutStorageState == 1) {
                            return "<span class='layui-btn layui-btn-warm layui-btn-xs'>执行中</span>";
                        }
                        if (d.F_OutStorageState == 2) {
                            return "<span class='layui-btn layui-btn-xs'>已下架</span>";
                        }
                        if (d.F_OutStorageState == 3) {
                            return "<span class='layui-btn layui-btn-danger layui-btn-xs'>已终止</span>";
                        }
                        if (d.F_OutStorageState == 4) {
                            return "<span class='layui-btn layui-btn-danger layui-btn-xs'>已完成</span>";
                        }
                    }
                },
                { field: 'F_OrderCode', title: '订单编号', width: 170, sort: true, filter: true },
                { field: 'F_Num', title: '数量', minWidth: 100, sort: true, filter: true },
                { field: 'F_CarNo', title: '车辆', width: 120, sort: true, filter: true },
                {
                    field: 'F_EnabledMark', title: '状态', width: 80, sort: true, filter: true,
                    templet: function (d) {
                        if (d.F_EnabledMark == true) {
                            return "<span class='layui-btn layui-btn-normal layui-btn-xs'>有效</span>";
                        } else {
                            return "<span class='layui-btn layui-btn-warm layui-btn-xs'>无效</span>";
                        }
                    }
                },
                {
                    field: 'F_CreatorTime', title: '创建时间', width: 160, sort: true, filter: { type: 'date[yyyy/MM/dd HH:mm:ss]' }, hide: true
                },
                { field: 'F_Description', title: '备注', minWidth: 120, sort: true, filter: true, hide: true },
            ]]
        });
        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            //执行搜索重载
            commonTable.reloadtable({
                elem: 'currentTableId',
                curr: 1,
                where: { keyword: data.field.txt_keyword }
            });
            return false;
        });
        wcLoading.close();
        //行点击事件监听，控制按钮显示
        var oneList = ["NF-delete", "NF-enabled", "NF-edit"];//选择1条显示
        commonTable.tableRowClick("radio", "currentTableFilter", "currentTableId", oneList);
        //toolbar监听事件
        table.on('toolbar(currentTableFilter)', function (obj) {
            var data = table.checkStatus('currentTableId').data;
            var id = data.length > 0 ? data[0].F_Id : null;
            if (obj.event === 'add') {  // 监听添加操作
                var parentform = window.name;
                common.modalOpen({
                    title: "添加出库单",
                    url: "/PlanManage/OutStoragePlan/AddForm?parentform=" + parentform + "&keyValue=" + keyValue + "&materialId=" + materialId,
                    width: "500px",
                    height: "550px",
                });
            }
            else if (obj.event === 'edit') {  // 监听添加操作
                var parentform = window.name;
                common.modalOpen({
                    title: "编辑出库单",
                    url: "/PlanManage/OutStoragePlan/AddForm?parentform=" + parentform + "&keyValue=" + keyValue + "&materialId=" + materialId + "&id=" + id,
                    width: "500px",
                    height: "550px",
                });
            }
            else if (obj.event === 'delete') {
                if (data.length == 0) {
                    common.modalMsg("未选中数据", "warning");
                    return false;
                }
                var ids = [];
                for (var i = 0; i < data.length; i++) {
                    ids.push(data[i].F_Id);
                }
                common.deleteForm({
                    url: "/PlanManage/OutStoragePlan/DeleteAddForm",
                    param: { keyValue: ids.join(',') },
                    success: function () {
                        table.reload('currentTableId', {}, true);
                    }
                });
            }
            else if (obj.event === 'enabled') {
                common.submitPost({
                    prompt: "注：您确定要【启动】该项单据吗？",
                    url: "/PlanManage/OutStoragePlan/EnabledForm",
                    param: { keyValue: data[0].F_Id },
                    success: function () {
                        table.reload('currentTableId', {}, true);
                    }
                });
            }
            return false;
        });
    });
</script>
